package com.wx.business.weixin.protocol;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.wx.business.weixin.common.Signature;
/**
 * 微信H5支付签名
 * @author Administrator
 *
 */
public class WxinPaySignatureDataH5 {

	private String nonceStr;
	
	private String package1;
	
	private String timeStamp;
	
	private String signType;
	
	private String paySign;
	
	private String appId;
	
	

	public WxinPaySignatureDataH5(String  prepayId,String noncestr,String timestamp,String appId ) {
		super();
		// 微信分配的公众号ID（开通公众号之后可以获取到）
		setAppId(appId);
		setSignType("MD5");
		
		setPackage1("prepay_id="+prepayId);
	    setNonceStr(noncestr);
	    setTimeStamp(timestamp);
		// 根据API给的签名规则进行签名
		String sign = Signature.getH5Sign(toMap());
		
		setPaySign(sign);
	}


	
	@Override
	public String toString() {
		return "WxinPaySignatureDataH5 [nonceStr=" + nonceStr + ", package1="
				+ package1 + ", timeStamp=" + timeStamp + ", signType="
				+ signType + ", paySign=" + paySign + ", appId=" + appId + "]";
	}



	public String getPackage1() {
		return package1;
	}

	public void setPackage1(String package1) {
		this.package1 = package1;
	}


	public String getNonceStr() {
		return nonceStr;
	}



	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}



	public String getTimeStamp() {
		return timeStamp;
	}



	public void setTimeStamp(String timeStamp) {
		this.timeStamp = timeStamp;
	}



	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}

	public String getPaySign() {
		return paySign;
	}

	public void setPaySign(String paySign) {
		this.paySign = paySign;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appid) {
		this.appId = appid;
	}


	
	

	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if (obj != null) {
					map.put(field.getName(), obj);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return map;
	}
	

	
}
